/**
 * 
 */
package com.sci.web.daoimpl;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.SqlMapClientCallback;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.ibatis.sqlmap.client.SqlMapExecutor;
import com.sci.web.bean.Check_Log;
import com.sci.web.bean.Enterprise_Benefit;

/**
 * @author  BaiFuyou
 * @date: Nov 4, 2011 9:59:22 AM
 */
public class DataReportM_BaseInfoDao extends SqlMapClientDaoSupport implements com.sci.web.dao.DataReportM_BaseInfoDao {

	/* (non-Javadoc)
	 * @see com.sci.web.dao.DataReportM_BaseInfoDao#getAllEnterprseBenefitByUserId(int)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Enterprise_Benefit> getAllEnterprseBenefitByUserId(int uid) {
		// TODO Auto-generated method stub
		return super.getSqlMapClientTemplate().queryForList("datereportseason.getallEn_Benefitbyuseid", uid);
	}

	@Override
	public boolean isDataIsExist(int uid, String year, int type) {
		// TODO Auto-generated method stub
		int length = -1;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("benefit_year", year);
		map.put("benefit_type", type);
		length = (Integer)super.getSqlMapClientTemplate().queryForObject("datereportseason.isbenifitdataisexite",map);
		return length > 0?true:false;
	}

	@Override
	public boolean insertNewBenefitData(Enterprise_Benefit eb) {
		// TODO Auto-generated method stub
		return (Integer)super.getSqlMapClientTemplate().insert("datereportseason.addnewbenefitdata",eb)>0?true:false;
	}

	@Override
	public int getEnterpriseId(int userid) {
		// TODO Auto-generated method stub
		return (Integer)super.getSqlMapClientTemplate().queryForObject("datereportseason.getenid", userid);
	}

	@Override
	public boolean updateEnterpriseBenefitDataById(Map<String, Object> map) {
		// TODO Auto-generated method stub
		System.out.println(map+"====updateEnterpriseBenefitDataById");
		int length = -1;
		length = (Integer)super.getSqlMapClientTemplate().update("datereportseason.updatebenefirdatabyid",map);
		System.out.println(length+"=length");
		return length>0?true:false;
	}

	@Override
	public boolean insertNewCheckLog(Check_Log cl) {
		// TODO Auto-generated method stub
		return (Integer)super.getSqlMapClientTemplate().insert("datereportseason.insertnewenterprise_check_log",cl)>0?true:false;
	}

	@Override
	public boolean updateEnterpriseStateForCheck(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return (Integer)super.getSqlMapClientTemplate().update("datereportseason.updatenterprisestatecheck",map)>0?true:false;
	}

	@Override
	public boolean updateEnterpriseStateForCheckBatch(final Map<String, Object> map,final Map<String, Object> map1) {
		// TODO Auto-generated method stub
		this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
			@Override
			public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
				// TODO Auto-generated method stub
				executor.startBatch();				
				executor.update("datereportseason.updatenterprisestatecheck",map1);
				executor.update("datereportseason.updatecheckenterprise_attachmenttable",map);
				executor.update("datereportseason.updatecheckenterprise_authenticationtable",map);
				executor.update("datereportseason.updatecheckenterprise_benefittable",map);
				executor.update("datereportseason.updatecheckenterprise_brandtable",map);
				executor.update("datereportseason.updatecheckenterprise_fundstable",map);
				executor.update("datereportseason.updatecheckenterprise_innovationtable",map);
				executor.update("datereportseason.updatecheckenterprise_labor_capacitytable",map);
				executor.update("datereportseason.updatecheckenterprise_managementtable",map);
				executor.update("datereportseason.updatecheckenterprise_newtable",map);
				executor.update("datereportseason.updatecheckenterprise_patenttable",map);
				executor.update("datereportseason.updatecheckenterprise_projecttable",map);
				executor.update("datereportseason.updatecheckenterprise_researchtable",map);
				executor.update("datereportseason.updatecheckenterprise_rewardtable",map);
				executor.update("datereportseason.updatecheckenterprise_standardtable",map);
				executor.update("datereportseason.updatecheckenterprise_strategyable",map);
				executor.executeBatch();
				return null;
			}
		});
		return false;
	}

}
